# 线程池: 一次性开辟一些线程, 用户直接给线程池提交任务, 线程任务的调度交给线程池来完成

from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor

# 任务函数
def fn(url):
    for i in range(1000):
        print(url, i)

if __name__ == '__main__':

    # ThreadPoolExecutor 换成 ProcessPoolExecutor 就是进程池
    # 创建线程池 (50 个线程)
    with ThreadPoolExecutor(50) as t:
        for i in range(100):
            t.submit(fn, url=f"线程{i}")

    # 等待线程池中的任务全部执行完毕, 才继续执行(守护)
    print("over")

